package com.example.demo.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.demo.entity.DTO.RoleAndWorkersAndBeautyCareDTO;
import com.example.demo.entity.DTO.RoleDTO;
import com.example.demo.entity.Role;
import com.example.demo.entity.VO.RoleVO;
import com.example.demo.result.Result;
import com.example.demo.service.IRoleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author Mr.wyy
 * @since 2024-06-03
 */
@Api(tags = "角色接口")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private IRoleService roleService;



    /**
     * 根据bc_id查询工作内容
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "查询护理师的工作内容和名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workersId",value = "组件id",required = true)
    })
    @GetMapping("/selectWorkerName")
    public Result<List<Role>> findWorkerName(@RequestParam Integer workersId) {
        RoleAndWorkersAndBeautyCareDTO WorkersAndBeautyCare = roleService.selectRoleAndWorkersAndBeautyCare(workersId) ;
        List<RoleAndWorkersAndBeautyCareDTO> list =  new ArrayList<>();
        list.add(WorkersAndBeautyCare);
        System.out.println(WorkersAndBeautyCare);
        return Result.success(list).msg("查询成功");
    }



    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "查询角色表所有数据")
    @GetMapping("/selectAll")
    public Result<List<Role>> findAll() {
        //查询所有角色信息
        List<Role> list = roleService.selectAllsRole();
        return Result.success(list).msg("查询成功");
    }

    /**
     * 根据id查询数据接口
     * @param roleId
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "根据roleId查询数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "组件id",required = true)
    })
    @GetMapping("/selectRoleById")
/*    @SaCheckLogin*/
    public Result<Role> selectRoleById(@RequestParam Integer roleId) {
        return Result.success().msg("查询成功").data( roleService.selectRoleById(roleId));
    }

 /*   *//**
     * 分页查询接口
     * @param pageNum
     * @param pageSize
     * @return
     *//*
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "分页查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页码",example="1",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页多少条",example="10",required = true)
    })
    @GetMapping("/page")
    public Result<MyPage<Role>> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        return Result.success().data(roleService.page(new Page<>(pageNum, pageSize), queryWrapper)).msg("查询成功");
    }*/

    /**
    * 新增
    * @param
    * @return
    */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public Result<Integer> add(@Valid @RequestBody RoleVO roleVO) {
        //新增角色
        Role role = new Role();
        RoleDTO roleDTO = new RoleDTO();
        BeanUtil.copyProperties(roleVO,role);
        roleDTO.setRoleName(role.getRoleName());
        roleDTO.setRoleKey(role.getRoleKey());
        roleDTO.setCreateTime(role.getCreateTime());
        int result = roleService.addRole(roleDTO);
        return Result.success(result).msg("添加成功");
    }

/*    *//**
     * 修改接口
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "根据id修改角色信息")
    @PutMapping("RoleUpdateById")
    public Result<RoleDTO> RoleUpdateById(@Valid @RequestBody Role role) {
        RoleDTO roleDTO = new RoleDTO();
        BeanUtil.copyProperties(role,roleDTO);
        //判断有没有这个角色
        if (roleService.selectRoleById(role.getRoleId()) == null) {
            return Result.error().msg("没有这个角色");
        }
        roleService.updateRole(roleDTO);
        return Result.success().msg("修改成功");
    }

    /**
     * 删除接口
     * @param roleId
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "删除接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "组件id",required = true)
    })
    @DeleteMapping("/RoleDeleteId")
    public Result<String> delete(@RequestParam Integer roleId) {
        roleService.deleteRole(roleId);
        return Result.success().msg("删除成功");
    }

    /**
     * 批量删除接口
     * @param ids
     * @return
     */
   /* @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "批量删除接口")
    @PostMapping("/del/batch")
    public Result<String> deleteBatch(@RequestBody List<Integer> ids) {
        roleService.removeByIds(ids);
        return Result.success().msg("批量删除成功");
    }*/
}